<?php

class ArticleModel extends Model {
	
	public function insert(array $article){
		$sql = "insert into ls_article (title,cate_id,author,summary,content,is_commend,is_self,is_private,is_index,is_caogao,
				del_flag,clicknum,commentnum,page_title,page_keywords,page_description,htmlpath,create_time,update_time) 
				value (?,?,?,?,?,?,?,?,?,?,0,1,0,?,?,?,?,?,?)";
		$params = array(array(1,$article['title'],PDO::PARAM_STR),
						array(2,$article['cateid'],PDO::PARAM_INT),
						array(3,$article['author'],PDO::PARAM_STR),
						array(4,$article['summary'],PDO::PARAM_STR),
						array(5,$article['content'],PDO::PARAM_STR),
						array(6,$article['is_commend'],PDO::PARAM_INT),
						array(7,$article['is_self'],PDO::PARAM_INT),
						array(8,$article['is_private'],PDO::PARAM_INT),
						array(9,$article['is_index'],PDO::PARAM_INT),
						array(10,$article['is_caogao'],PDO::PARAM_INT),
						array(11,$article['page_title'],PDO::PARAM_STR),
						array(12,$article['page_keywords'],PDO::PARAM_STR),
						array(13,$article['page_description'],PDO::PARAM_STR),
						array(14,$article['htmlpath'],PDO::PARAM_STR),
						array(15,$article['create_time'],PDO::PARAM_STR),
						array(16,$article['update_time'],PDO::PARAM_STR),
					);
		return $this->pdo->executeNonQuery($sql,$params);
	}
	
	public function update(array $article){
		$sql = "update ls_article set title=?,cate_id=?,author=?,summary=?,content=?,is_commend=?,is_self=?,is_private=?,
				is_index=?,is_caogao=?,page_title=?,page_keywords=?,page_description=?,htmlpath=?,create_time=?
				where art_id=?";
		$params = array(array(1,$article['title'],PDO::PARAM_STR),
						array(2,$article['cateid'],PDO::PARAM_INT),
						array(3,$article['author'],PDO::PARAM_STR),
						array(4,$article['summary'],PDO::PARAM_STR),
						array(5,$article['content'],PDO::PARAM_STR),
						array(6,$article['is_commend'],PDO::PARAM_INT),
						array(7,$article['is_self'],PDO::PARAM_INT),
						array(8,$article['is_private'],PDO::PARAM_INT),
						array(9,$article['is_index'],PDO::PARAM_INT),
						array(10,$article['is_caogao'],PDO::PARAM_INT),
						array(11,$article['page_title'],PDO::PARAM_STR),
						array(12,$article['page_keywords'],PDO::PARAM_STR),
						array(13,$article['page_description'],PDO::PARAM_STR),
						array(14,$article['htmlpath'],PDO::PARAM_STR),
						array(15,$article['update_time'],PDO::PARAM_STR),
						array(16,$article['art_id'],PDO::PARAM_INT),
					);
		return $this->pdo->executeNonQuery($sql,$params);
	}
	
	public function getScrollData(){
		$sql = "select a.art_id,a.title,a.cate_id,a.author,a.is_commend,a.is_self,a.is_private,a.is_index,a.clicknum,a.commentnum,a.create_time,
				c.catename from ls_article a,ls_category c where a.cate_id=c.cate_id order by a.art_id desc";
		return $this->pdo->fetchAllBoth($sql);
	}
	
	public function select($art_id){
		$sql = "select * from ls_article where art_id = ?";
		$params = array(array(1,$art_id,PDO::PARAM_INT));
		return $this->pdo->fetchBoth($sql,$params);
	}
}